package com.kaka.bus.engine.repay;

import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.constant.Constant;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;
import com.kaka.bus.util.logger.Logger;

import javax.inject.Inject;

/**
 * Created by OnionMac on 2018/1/18.
 */

public class RepayPresenter extends RxPresenter<RepayContract.View> implements RepayContract.Presenter{

    @Inject
    public RepayPresenter(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public void getParams(String userId, String amount, String conctact_id, String bankId, String cardNo, String tokenKey,String token) {
        mView.showDialog("正在提交付款申请...");

        addSubscribe(mDataManager
                .getApi()
                .repayment(userId,amount,conctact_id,bankId,cardNo,tokenKey,token, Constant.PLATFORM)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> wrapper) {
                        mView.getParamsSuccess(wrapper);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                }));
    }

    @Override
    public void getInfo(String userId, String brrow_id,String token,int type) {
        mView.showDialog("正在读取付款信息...");
        Logger.i("呵呵");
        addSubscribe(mDataManager
                .getApi()
                .getRepaymentDetails(userId,brrow_id,token,type)
                .compose(T.D())
                .subscribeWith(new Result<String>() {
                    @Override
                    protected void onSuccess(String wrapper) {
                        mView.getRepaymentSuccess(wrapper);
                        Logger.i("成功");
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        Logger.i("失败");
                        mView.dissDialog();
                    }
                }));

    }
}
